Page({
  data: {
    value: '',
    list_value: '',
    avatarUrl: '',
    username: '',
    images: '',
  },
  onLoad: function (query) {
    this.setData({
      value: query.area_value,
      avatarUrl: query.avatarUrl,
      username: query.username,
      is_true: query.is_true,
      images: query.images,
      width: query.width,
      height: query.height,
      top: query.top,
      left: query.left,
      num: query.num,
    });
    // console.log(this.data.is_true, this.data.width, this.data.height, this.data.left, this.data.top, this.data.num, this.data.images)
  },
  onShow: function () {
    var _this = this
    setTimeout(function () {
      _this.getHeight();
    }, 100)
  },
  util: function (obj) {
    // console.log(obj, -obj.list, obj.container);
    var continueTime = (parseInt(obj.list / obj.container) + 1) * 5000;
    var setIntervalTime = 50 + continueTime;
    var animation = tt.createAnimation({
      duration: 200,  // 动画时长
      timingFunction: "linear", // 线性
      delay: 10  // 0则不延迟
    });
    this.animation = animation;
    animation.translateY(obj.container)
      .step({ duration: 50, timingFunction: 'step-start' })
      .translateY(-obj.list)
      .step({ duration: continueTime });
    this.setData({
      animationData: animation.export()
    })
    setInterval(() => {
      animation.translateY(obj.container)
        .step({ duration: 50, timingFunction: 'step-start' })
        .translateY(-obj.list)
        .step({ duration: continueTime });
      this.setData({
        animationData: animation.export()
      })
    }, setIntervalTime)
  },
  getHeight() {
    var obj = new Object();
    //创建节点选择器
    var query = tt.createSelectorQuery();
    query.select('.container').boundingClientRect()
    query.select('.list').boundingClientRect()
    query.exec((res) => {
      obj.container = res[0].height; // 框的height
      obj.list = res[1].height; // list的height
      this.util(obj);
    })
  },
  // 点击完成
  compile: function (e) {
    this.setData({
      list_value: this.data.value
    })
    tt.navigateTo({
      url: '../../pages/newCard_ok/newCard_ok?value=' + this.data.list_value
        //  + '&username=' + this.data.username
        //  + '&avatarUrl=' + this.data.avatarUrl
        + '&images=' + this.data.images
        + '&is_true=' + this.data.is_true
        + '&width=' + this.data.width
        + '&height=' + this.data.height
        + '&left=' + this.data.left
        + '&top=' + this.data.top
        + '&num=' + this.data.num,
    });
  },
  back() {
    wx.navigateBack({
      delta: 1
    })
  },
})